package com.prd.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.prd.dto.EntMeetDto;
import com.prd.dto.MatterDto;
import com.prd.dto.SummaryVoteDto;
import com.prd.model.*;
import com.prd.service.*;
import com.prd.util.AjaxResult;
import com.prd.util.TableDataInfo;
import com.prd.vo.EntMeetVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "会议管理")
@RestController
@RequestMapping("/api/entMeet")
public class EntMeetController extends BaseController {

    @Autowired
    private EntMeetService entMeetService;

    @Autowired
    private EntMeetSummaryMotionService entMeetSummaryMotionService;

    @Autowired
    private EntInviteService entInviteService;

    @Autowired
    private EntMeetMakeService entMeetMakeService;

    @Autowired
    private EntMeetSignService entMeetSignService;

    @ApiOperation("查询列表")
    @GetMapping(value = "list", produces = "application/json;charset=UTF-8")
    public TableDataInfo list(EntMeetDto entMeetDto) {
        startPage();
        List<EntMeetVo> list = entMeetService.listInfo(entMeetDto);
        return getDataPage(list);
    }

    @ApiOperation("添加会议")
    @PostMapping(value = "add", produces = "application/json;charset=UTF-8")
    public AjaxResult add(@RequestBody EntMeet entMeet) {
        return toAjax(entMeetService.insertEntMeet(entMeet));
    }

    @ApiOperation("修改会议")
    @PostMapping(value = "update", produces = "application/json;charset=UTF-8")
    public AjaxResult update(@RequestBody EntMeet entMeet) {
        return toAjax(entMeetService.updateEntMeet(entMeet));
    }

    @ApiOperation("删除会议")
    @PostMapping(value = "delete/{id}", produces = "application/json;charset=UTF-8")
    public AjaxResult delete(@PathVariable Long id) {
        return toAjax(entMeetService.removeById(id));
    }

    @ApiOperation("查询详细信息")
    @GetMapping(value = "{id}", produces = "application/json;charset=UTF-8")
    public AjaxResult detail(@PathVariable Long id) {
        return AjaxResult.success(entMeetService.detail(id));
    }

    @ApiOperation("我要签到")
    @PostMapping(value = "signIn/{id}", produces = "application/json;charset=UTF-8")
    public AjaxResult signIn(@PathVariable Long id) {
        return toAjax(entMeetService.signIn(id));
    }

    @ApiOperation("取消会议")
    @PostMapping(value = "cancel/{id}", produces = "application/json;charset=UTF-8")
    public AjaxResult cancelMeet(@PathVariable Long id) {
        return toAjax(entMeetService.cancelMeet(id));
    }

    @ApiOperation("添加邀请外部人员")
    @PostMapping(value = "outside", produces = "application/json;charset=UTF-8")
    public AjaxResult outside(@RequestBody List<EntInvite> inviteList) {
        return toAjax(entMeetService.outside(inviteList));
    }

    @ApiOperation("签离")
    @PostMapping(value = "visa/{id}", produces = "application/json;charset=UTF-8")
    public AjaxResult visa(@PathVariable Long id) {
        return toAjax(entMeetService.visa(id));
    }

    @ApiOperation("添加会议记录及事项决议")
    @PostMapping(value = "addMatter", produces = "application/json;charset=UTF-8")
    public AjaxResult addMatter(@RequestBody MatterDto matterDto) {
        return toAjax(entMeetService.addMatter(matterDto));
    }

    @ApiOperation("会议请假")
    @PostMapping(value = "leave/{id}", produces = "application/json;charset=UTF-8")
    public AjaxResult leave(@PathVariable Long id) {
        return toAjax(entMeetService.leave(id));
    }

    @ApiOperation("会议开始")
    @PostMapping(value = "start/{id}", produces = "application/json;charset=UTF-8")
    public AjaxResult start(@PathVariable Long id) {
        return toAjax(entMeetService.start(id));
    }

    @ApiOperation("结束会议")
    @PostMapping(value = "conclude/{id}", produces = "application/json;charset=UTF-8")
    public AjaxResult conclude(@PathVariable Long id) {
        return toAjax(entMeetService.conclude(id));
    }

    @ApiOperation("查询会议记录及事项决议")
    @GetMapping(value = "listMatter/{meetId}", produces = "application/json;charset=UTF-8")
    public AjaxResult listMatter(@PathVariable Long meetId) {
        return AjaxResult.success(entMeetService.listMatter(meetId));
    }

    @ApiOperation("查询会议人员权限")
    @GetMapping(value = "jurisdiction/{meetId}", produces = "application/json;charset=UTF-8")
    public AjaxResult jurisdiction(@PathVariable Long meetId) {
        return AjaxResult.success(entMeetService.jurisdiction(meetId));
    }

    @ApiOperation("添加人事酝酿/动议")
    @PostMapping(value = "addMotion", produces = "application/json;charset=UTF-8")
    public AjaxResult addMotion(@RequestBody EntMeetSummaryMotion entMeetSummaryMotion) {
        return toAjax(entMeetSummaryMotionService.insertInfo(entMeetSummaryMotion));
    }

    @ApiOperation("查询外部人员")
    @GetMapping(value = "external", produces = "application/json;charset=UTF-8")
    public AjaxResult external(String search) {
        return AjaxResult.success(entInviteService.external(search));
    }

//    @ApiOperation("查询内部人员")
//    @GetMapping(value = "external", produces = "application/json;charset=UTF-8")
//    public AjaxResult external(String search) {
//        return AjaxResult.success(entInviteService.external(search));
//    }

    @ApiOperation("会议抄送")
    @PostMapping(value = "addMake", produces = "application/json;charset=UTF-8")
    public AjaxResult addMake(@RequestBody EntMeetMake entMeetMake) {
        return toAjax(entMeetMakeService.insertInfo(entMeetMake));
    }

    @ApiOperation("查询会议抄送记录")
    @GetMapping(value = "listMake/{meetId}", produces = "application/json;charset=UTF-8")
    public TableDataInfo listMake(@PathVariable("meetId") Long meetId) {
        startPage();
        LambdaQueryWrapper<EntMeetMake> lambdaQueryWrapper = new LambdaQueryWrapper();
        lambdaQueryWrapper.eq(EntMeetMake::getMeetId, meetId);
        List<EntMeetMake> list = entMeetMakeService.list(lambdaQueryWrapper);
        return getDataPage(list);
    }

    @ApiOperation("添加决议投票人员")
    @PostMapping(value = "addSummaryVote", produces = "application/json;charset=UTF-8")
    public AjaxResult addSummaryVote(@RequestBody SummaryVoteDto summaryVoteDto) {
        return toAjax(entMeetService.addSummaryVote(summaryVoteDto));
    }

    @ApiOperation("添加决议上报审批人")
    @PostMapping(value = "addSummaryAppear", produces = "application/json;charset=UTF-8")
    public AjaxResult addSummaryAppear(@RequestBody EntMeet entMeet) {
        if (entMeet.getId() == null || StringUtils.isBlank(entMeet.getSummaryApprove())) {
            AjaxResult.error("参数不能为空！");
        }
        return toAjax(entMeetService.addSummaryAppear(entMeet.getId(), entMeet.getSummaryApprove()));
    }

    @ApiOperation("添加会议内部参会人员")
    @PostMapping(value = "addMeetInterior", produces = "application/json;charset=UTF-8")
    public AjaxResult addMeetInterior(@RequestBody EntMeet entMeet) {
        if (entMeet.getId() == null || StringUtils.isBlank(entMeet.getInteriorPersonnel())) {
            AjaxResult.error("参数不能为空！");
        }
        return toAjax(entMeetService.addMeetInterior(entMeet.getId(), entMeet.getInteriorPersonnel()));
    }

    @ApiOperation("添加会议外部参会人员")
    @PostMapping(value = "addMeetExternal", produces = "application/json;charset=UTF-8")
    public AjaxResult addMeetExternal(@RequestBody EntMeet entMeet) {
        if (entMeet.getId() == null || StringUtils.isBlank(entMeet.getExternalPersonnel())) {
            AjaxResult.error("参数不能为空！");
        }
        return toAjax(entMeetService.addMeetExternal(entMeet.getId(), entMeet.getExternalPersonnel()));
    }

    @ApiOperation("查询会议出席情况")
    @GetMapping(value = "listMeetPresent/{meetId}/{type}", produces = "application/json;charset=UTF-8")
    public AjaxResult listMeetPresent(@PathVariable("meetId") Long meetId, @PathVariable("type") Integer type) {
        return AjaxResult.success(entMeetService.listMeetPresent(meetId, type));
    }
}
